﻿using FPSO.Models.Constant;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FPSO.Models.Domain
{
    public class ManualCalcResult
    {
        public ShipCalcState ShipCalc { get; set; }
		public List<TankCalcState> tankCalcStates = new List<TankCalcState>();

        public ManualCalcResult()
        {
            ShipCalc = new ShipCalcState();
			List<TankConstant.ConstantTankInfo> constantlists  = TankConstant.ConstantList;
			foreach(TankConstant.ConstantTankInfo constantlist in constantlists)
			{
				tankCalcStates.Add(new TankCalcState(constantlist.TankAbName));
			}
        }

        public ShipDraught GetCalcDraught()
        {
            ShipDraught draught = new ShipDraught();
			//DEBUG 这里临时这么处理
			double corr = 27.6 * Math.Sin(ShipCalc.Heel);
			draught.MidPDraft = ShipCalc.TM + corr;
            draught.MidSDraft = ShipCalc.TM - corr;
			draught.AftPDraft = ShipCalc.TM + ShipCalc.Trim / 2 + corr;
			draught.AftSDraft = ShipCalc.TM + ShipCalc.Trim / 2 - corr;
			draught.FwdPDraft = ShipCalc.TM - ShipCalc.Trim / 2 + corr;
			draught.FwdSDraft = ShipCalc.TM - ShipCalc.Trim / 2 - corr;

            draught.Heel = ShipCalc.Heel * 57.3;
            draught.Trim = ShipCalc.Trim;
            return draught;
        }

		//返回船舶状态计算及校核结果
		public bool GetShipCheckStatus()
		{
			return true;
		}

		//返回舱室状态计算及校核结果
		public bool GetTankCheckStatus()
		{
			return true;
		}

		//麻烦张工按照这个思路改
		public void SetTankCalcState(TankCalcState tankstate)
		{
			List<TankConstant.ConstantTankInfo> constantlists = TankConstant.ConstantList;
			//DEBUG 临时封掉
			//if (tankCalcStates.Count() == constantlists.Count())
			{
				for (int i = 0; i < constantlists.Count(); i++)
				{
					TankConstant.ConstantTankInfo constantlist = constantlists[i];
					if (constantlist.TankAbName == tankstate.Abname)
					{
						tankCalcStates[i] = tankstate;
					}
				}
			}
		}
        public void SetTankCalcStateById(TankCalcState tankstate,string tankId)
        {
            List<TankConstant.ConstantTankInfo> constantlists = TankConstant.ConstantList;
			//DEBUG 临时封掉
			//if (tankCalcStates.Count() == constantlists.Count())
            {
                for (int i = 0; i < constantlists.Count(); i++)
                {
                    TankConstant.ConstantTankInfo constantlist = constantlists[i];
                    if (constantlist.TankID == tankId)
                    {
						tankstate.Abname = constantlist.TankAbName;
                        tankCalcStates[i] = tankstate;
						break;
                    }
                }
            }
        }
        public TankCalcState GetTankCalcState(string tankId)
        {
			List<TankConstant.ConstantTankInfo> constantlists = TankConstant.ConstantList;
			//DEBUG 临时封掉
			//if (tankCalcStates.Count() == constantlists.Count())
			{
				for(int i=0;i< constantlists.Count();i++)
				{
					TankConstant.ConstantTankInfo constantlist = constantlists[i];
					if(constantlist.TankID == tankId)
					{
						return tankCalcStates[i];
					}
				}
			}
			return null;
        }

        public TankCalcState GetTankCalcStateByName(string tankName)
        {
            List<TankConstant.ConstantTankInfo> constantlists = TankConstant.ConstantList;
			//DEBUG 临时封掉
			//if (tankCalcStates.Count() == constantlists.Count())
			{
				for (int i = 0; i < constantlists.Count(); i++)
                {
                    TankConstant.ConstantTankInfo constantlist = constantlists[i];
                    if (constantlist.TankAbName == tankName || constantlist.TankName == tankName)
                    {
                        return tankCalcStates[i];
                    }
                }
            }
            return null;
        }
    }
}
